/*
 * @lc app=leetcode.cn id=101 lang=cpp
 *
 * [101] 对称二叉树
 */
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

class Solution
{
  private:
    bool judge(TreeNode *root1, TreeNode *root2)
    {
        if (root1 == nullptr) {
            if (root2 == nullptr) {
                return true;
            }
            return false;
        }

        if (root2 == nullptr) {
            if (root1 == nullptr) {
                return true;
            }
            return false;
        }

        if (root1->val != root2->val) {
            return false;
        }
        if (judge(root1->left, root2->right) == false) {
            return false;
        }
        if (judge(root1->right, root2->left) == false) {
            return false;
        }
        return true;
    }

  public:
    bool isSymmetric(TreeNode *root) { return judge(root, root); }
};
// @lc code=end
